package com.hghivln.erpwarehouse.system.controller;


import com.hghivln.erpwarehouse.system.common.lang.Result;
import com.hghivln.erpwarehouse.system.service.LoginfoService;
import com.hghivln.erpwarehouse.system.vo.LoginfoVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hghivln
 * @since 2021-06-25
 */
@RestController
@RequestMapping("/api/loginfo")
public class LoginfoController {

    @Autowired
    private LoginfoService loginfoService;

    @RequestMapping("loadAllLoginfo")
    public Object loadAllLoginfo(LoginfoVo loginfoVo) {
        return loginfoService.queryAllLoginfo(loginfoVo);
    }

    @RequiresPermissions("loginfo:delete")
    @RequestMapping("deleteLoginfo")
    public Result deleteLoginfo(Integer id) {
        try {
            loginfoService.removeById(id);
            return Result.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.DELETE_ERROR;
        }
    }

    @RequiresPermissions("loginfo:batchdelete")
    @RequestMapping("batchDeleteLoginfo")
    public Result batchDeleteLoginfo(Integer[] ids) {
        try {
            Collection<Serializable> idList = new ArrayList<>(Arrays.asList(ids));
            loginfoService.removeByIds(idList);
            return Result.DELETE_SUCCESS;
        } catch (Exception e) {
            e.printStackTrace();
            return Result.DELETE_ERROR;
        }
    }
}
